import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import Routers from './router'
import VueMarkdown from 'vue-markdown'
import iView from 'ivueui'
import 'ivueui/dist/styles/iview.css'
import IEcharts from 'vue-echarts-v3'
import Ajax from './libs/ajax'
import Config from './config/config'
import _Vuex from 'vuex'
import VuexConfig from './config/VuexConfig'

Vue.use(VueRouter)
Vue.use(iView)
Vue.use(_Vuex)
Vue.use(VueMarkdown)
Vue.use(IEcharts)

const Vuex = new _Vuex.Store({state:VuexConfig})

Vue.prototype.$config = Config
Vue.prototype.$ajax = Ajax
Vue.prototype.Vuex = Vuex

Vue.config.productionTip = false

// 路由配置
const RouterConfig = {
  mode: 'history',
  routes: Routers
}
const router = new VueRouter(RouterConfig)
router.beforeEach((to, from, next) => {
  iView.LoadingBar.start()
  Vuex.state._loding = true
  let title = to.meta.title + ' - TalkingCoder'
  window.document.title = title
  next()
})
router.afterEach(() => {
  iView.LoadingBar.finish()
	setTimeout(function(){
		Vuex.state._loding = false
	}.bind(Vuex),500);
  window.scrollTo(0, 0)
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  VueMarkdown,
  render: h => h(App)
})
